<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Project</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="lib/fxsupport.js"></script>
<script type="text/javascript" src="lib/jquery-1.8.3.js"></script>
<script type="text/javascript" src="lib/JSResource.js"></script>
<script type="text/javascript" src="lib/urlpara.js"></script>
<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* 此 1px 负边距可以放置在此布局中的任何列中，且具有相同的校正效果。 */
ul.nav a { zoom: 1; }  /* 缩放属性将为 IE 提供其需要的 hasLayout 触发器，用于校正链接之间的额外空白 */
</style>
<![endif]-->
</head>

<body>

	<div class="container">
		<div class="header">
			<a href="#"><img src="logo.jpg" alt="在此处插入徽标" name="Insert_logo"
				width="20%" height="90" id="Insert_logo"
				style="background-color: #8090AB; display:block;" /> </a>
			<!-- end .header -->
		</div>
		<div class="sidebar1">
			<ul class="nav">
				<li><a href="home.jsp">Department Home</a></li>
				<li><a href="contributorlist.htm">Contributor List</a></li>
				<li><a href="memberlist.htm">Member List</a></li>
			</ul>
			<!-- end .sidebar1 -->
		</div>
		<div class="content">
			<form name="form">
				id: <input type="text" name="id" id="id"><br> name: <input
					type="text" name="name" id="name"><br> start: <select
					id="tYEAR1" size="1" onChange="createSelect1()"></select> <select
					id="tMON1" size="1" onChange="createSelect1()"></select> <select
					id="tDAY1" size="1"></select><br> end: <select id="tYEAR2"
					size="1" onChange="createSelect2()"></select> <select id="tMON2"
					size="1" onChange="createSelect2()"></select> <select id="tDAY2"
					size="1"></select><br> <input name="commit" type="button"
					value="submit" onClick="commitPage()">
			</form>
			<!-- end .content -->
		</div>
		<div class="footer">
			<!-- end .footer -->
		</div>
		<!-- end .container -->
	</div>
	<script type="text/javascript">
		function createSelect1(ActionFlag) {
			var selYear = document.getElementById("tYEAR1");
			var selMonth = document.getElementById("tMON1");
			var selDay = document.getElementById("tDAY1");
			var dt = new Date();

			if (ActionFlag == 1) {
				MinYear = 1980;
				MaxYear = MinYear + 100;

				for ( var i = MinYear; i <= MaxYear; i++) {
					var op = document.createElement("OPTION");
					op.value = i;
					op.innerHTML = i;
					selYear.appendChild(op);
				}
				selYear.selectedIndex = dt.getFullYear() - 1980;

				for ( var i = 1; i < 13; i++) {
					var op = document.createElement("OPTION");
					op.value = i;
					op.innerHTML = i;
					selMonth.appendChild(op);
				}
				selMonth.selectedIndex = dt.getMonth();
			}

			var date = new Date(selYear.value, selMonth.value, 0);
			var daysInMonth = date.getDate();
			selDay.options.length = 0;

			for ( var i = 1; i <= daysInMonth; i++) {
				var op = document.createElement("OPTION");
				op.value = i;
				op.innerHTML = i;
				selDay.appendChild(op);
			}

			selDay.selectedIndex = dt.getDate() - 1;
		}
		createSelect1(1);
		function createSelect2(ActionFlag) {
			var selYear = document.getElementById("tYEAR2");
			var selMonth = document.getElementById("tMON2");
			var selDay = document.getElementById("tDAY2");
			var dt = new Date();

			if (ActionFlag == 1) {
				MinYear = 1980;
				MaxYear = MinYear + 100;

				for ( var i = MinYear; i <= MaxYear; i++) {
					var op = document.createElement("OPTION");
					op.value = i;
					op.innerHTML = i;
					selYear.appendChild(op);
				}
				selYear.selectedIndex = dt.getFullYear() - 1980;

				for ( var i = 1; i < 13; i++) {
					var op = document.createElement("OPTION");
					op.value = i;
					op.innerHTML = i;
					selMonth.appendChild(op);
				}
				selMonth.selectedIndex = dt.getMonth();
			}

			var date = new Date(selYear.value, selMonth.value, 0);
			var daysInMonth = date.getDate();
			selDay.options.length = 0;

			for ( var i = 1; i <= daysInMonth; i++) {
				var op = document.createElement("OPTION");
				op.value = i;
				op.innerHTML = i;
				selDay.appendChild(op);
			}

			selDay.selectedIndex = dt.getDate() - 1;
		}
		createSelect2(1);
		var id = getParamFromURL("id");
		if (id != "") {
			resource
					.GET(
							"contract/project/" + id,
							function() {
								document.getElementById("id").value = id;
								document.getElementById("id").disabled = true;
								document.getElementById("name").value = resource
										.getColumnValue("name");
								var startpart = resource
										.getColumnValue("start").split("-");
								document.getElementById("tYEAR1").selectedIndex = parseInt(startpart[0]) - 1980;
								document.getElementById("tMON1").selectedIndex = parseInt(startpart[1]) - 1;
								document.getElementById("tDAY1").selectedIndex = parseInt(startpart[2]) - 1;
								var endpart = resource.getColumnValue("end")
										.split("-");
								document.getElementById("tYEAR2").selectedIndex = parseInt(endpart[0]) - 1980;
								document.getElementById("tMON2").selectedIndex = parseInt(endpart[1]) - 1;
								document.getElementById("tDAY2").selectedIndex = parseInt(endpart[2]) - 1;
							});
		}
		function commitPage() {
			var name = document.getElementById("name").value;
			var yr = document.getElementById("tYEAR1");
			var mth = document.getElementById("tMON1");
			var day = document.getElementById("tDAY1");
			var start = yr.options[yr.selectedIndex].value + "-"
					+ mth.options[mth.selectedIndex].value + "-"
					+ day.options[day.selectedIndex].value;
			var yr1 = document.getElementById("tYEAR2");
			var mth1 = document.getElementById("tMON2");
			var day1 = document.getElementById("tDAY2");
			var end = yr1.options[yr1.selectedIndex].value + "-"
					+ mth1.options[mth1.selectedIndex].value + "-"
					+ day1.options[day1.selectedIndex].value;
			if (yr1.selectedIndex < yr.selectedIndex
					|| (yr1.selectedIndex == yr.selectedIndex && mth1.selectedIndex < mth.selectedIndex)
					|| (yr1.selectedIndex == yr.selectedIndex
							&& mth1.selectedIndex == mth.selectedIndex && day1.selectedIndex < day.selectedIndex)) {
				alert("End date shoulf be after start date!");
				return;
			}
			if (checkIfNull(name)) {
				alert("Please fill in all the blanks!");
				return;
			}
			if (id != "") {
				putProject(id, name, start, end, reloadReferrer);
			} else {
				id = document.getElementById("id").value;
				if (id == "") {
					alert("Please fill in all the blanks!");
					return;
				}
				if (!checkIfInt(id)) {
					alert("Id should be an integer value!");
					id = "";
					return;
				}
				resource.GET("contract/project/" + id, function() {
					if (resource.getColumns().length != 0) {
						alert("This id exists. Please choose another id!");
						id = "";
						return;
					}
					postProject(id, name, start, end, reloadReferrer);
				});
			}
		}
	</script>
</body>
</html>
